package no.ntnu.idi.deid.decision.validators;

import no.ntnu.idi.deid.documentunits.Sentence;
import no.ntnu.idi.deid.documentunits.Token;
import no.ntnu.idi.deid.searchresultunits.CategoryTag;
import no.ntnu.idi.deid.searchresultunits.Tag;

public class Filters {
	
	private Filters() {
		
	}
	
	public static void zipCodeAndYearFilter(Token token) {
		if(token.containsCategoryTag(Tag.ZIPCODE) && 
				token.containsCategoryTag(Tag.YEAR) ) {
			Token tokenBefore = token.getSentence().getTokenWithIndex(token.getIndex());
			if(tokenBefore != null) {
				if(tokenBefore.strippedTokenEquals("i") || tokenBefore.strippedTokenEquals("I")) {
					token.removeTag(Tag.ZIPCODE);
				}
			}

		}
	}
	
	/**
	 * 
	 * @param sentence The sentence to investigate
	 * @param threshold a percentage threshold value
	 * @return sensitive compared to the threshold value
	 */
	public static boolean isSentenceSensitiv(Sentence sentence, double threshold) {
		int numberOfSensitiveTokens = 0;
		for(int i=0; i < sentence.size();i++) {
			if(sentence.get(i).isSensitiv()) {
				numberOfSensitiveTokens++;
			}
		}
		double sensetivityPercentage = (double)numberOfSensitiveTokens/(double)sentence.size();
		if(sensetivityPercentage > threshold ) {
			return true;
		}
		else {
			return false;
		}
		
	}
	
	public static boolean firstLetterIsUpperCase(Token token) {
		if(Character.isUpperCase(token.getOrginal().charAt(0)) && token.getSentence().getStartIndex() != token.getIndex()) {
			return true;
		}
		return false;
	}
	
	public static boolean isAllCategoriesSensitive(Token t) {
		for(CategoryTag tag: t) {
			if(!tag.isSensitive()){
				return false;
			}
		}
		return true;
	}
	
	public static boolean isAllCategoriesInSensitive(Token t) {
		for(CategoryTag tag: t) {
			if(tag.isSensitive()){
				return false;
			}
		}
		return true;
	}
}
